package com.youyou.fusheng2.View.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.makeramen.roundedimageview.RoundedImageView;
import com.youyou.fusheng2.R;

import java.util.List;

/**
 * @ProjectName: Fusheng
 * @Package: com.ssj.fusheng.Adapter
 * @ClassName: mineAdapter
 * @Description:
 * @Author:
 * @CreateDate: 2020-03-02 16:32
 * @UpdateDate: 2020-03-02 16:32
 * @Version: 1.0
 */
public class mineAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private static final int                 FLAGE_ONE = 0;
    private static final int                 FLAGE_THR = 2;
    private              Context             context;
    private              List<String>        listtou;
    private              List<String>        listitem;
    private              OnItemClickListener mClickListener;

    public interface OnItemClickListener {
         void onItemClick(int postion);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mClickListener = listener;
    }

    public mineAdapter(Context context, List<String> listtou, List<String> listitem) {
        this.context = context;
        this.listtou = listtou;
        this.listitem = listitem;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        if (viewType == FLAGE_ONE) {
            return new Hearder(LayoutInflater.from(parent.getContext()).inflate(R.layout.mine_tx, parent, false));
        }
        if (viewType == FLAGE_THR) {
            return new FFooter(LayoutInflater.from(parent.getContext()).inflate(R.layout.mine_list_item, parent, false));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof Hearder) {
            Glide.with(context).load(listtou.get(position)).into(((Hearder) holder).touxiang);
            ((Hearder) holder).tv_nc.setText("铁臂阿童木");
            ((Hearder) holder).touxiang.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });
        }
        if (holder instanceof FFooter) {
            ((FFooter) holder).mine_item_tv.setText(listitem.get(position - 1));
            ((FFooter) holder).mine_item_tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mClickListener.onItemClick(position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return listitem.isEmpty()?0:listitem.size()+1;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return FLAGE_ONE;
        }  else if (position == 2) {
            return FLAGE_THR;
        } else {
            return FLAGE_THR;
        }
    }


    public class Hearder extends RecyclerView.ViewHolder {

        private RoundedImageView touxiang;
        private TextView         tv_nc;

        public Hearder(@NonNull View itemView) {
            super(itemView);
            touxiang = itemView.findViewById(R.id.touxiang);
            tv_nc = itemView.findViewById(R.id.tv_nc);
        }
    }


    public class FFooter extends RecyclerView.ViewHolder {

        private TextView mine_item_tv;

        public FFooter(@NonNull View itemView) {
            super(itemView);
            mine_item_tv = itemView.findViewById(R.id.mine_item_tv);

        }
    }



}

